<template>
	<!--顶部区域-->
	<view class="smart-panel-head">
		<view class="smart-panel-head-title">checkarea</view>
	</view>
	<!--主题-->
    <view class="smart-padding-wrap">
        <view>默认样式</view>
        <checkbox-group>
            <checkbox value="cb1" checked="true" />选中
            <checkbox value="cb" />未选中
        </checkbox-group>

        <view class="smart-page-head-title">不同颜色和尺寸的checkbox</view>
        <checkbox-group>
            <label style="background-color: #8A6DE9;">
                <checkbox value="cb1" checked="true" style="transform:scale(0.7)" />选中
            </label>
            <label style="background-color: #00ff00;">
                <checkbox value="cb" style="transform:scale(0.7)" />未选中
            </label>
        </checkbox-group>

        <view>推荐展示样式</view>
        <view class="uni-list">
            <checkbox-group @change="checkboxChange">
                <label class="uni-list-cell uni-list-cell-pd" v-for="item in items" :key="item.value" style="background-color: #F3A73F;">
                    <checkbox :value="item.value" :checked="item.checked" />
                    {{item.name}}
                </label>
            </checkbox-group>
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            items: [
                {value: 'USA', name: '美国', checked: false},
                {value: 'CHN', name: '中国', checked: false},
                {value: 'BRA', name: '巴西', checked: false},
                {value: 'JPN', name: '日本', checked: false},
                {value: 'ENG', name: '英国', checked: false},
                {value: 'FRA', name: '法国', checked: false}
            ]
        }
    },
    methods: {
        checkboxChange: function (e) {
            var items = this.items,
            values = e.detail.value;
            for (var i = 0, lenI = items.length; i < lenI; ++i) {
                const item = items[i]
				if(values.indexOf(item.value) >= 0){
				    this.$set(item,'checked',true)
				}else{
				    this.$set(item,'checked',false)
				}
                console.log('i: '+i+'---'+item.name+', index:'
                + values.indexOf(item.value)
                +', isCheck: '+item.checked)
               
            }
        }
    }
}
</script>

<style>
	
	
	.uni-list {
	    background-color: #FFFFFF;
	    border-radius: 10rpx;
	}
	
	.uni-list-cell {
	    display: flex;
	    align-items: center;
	    padding: 20rpx;
	}
	
	.uni-list-cell-pd {
	    padding: 20rpx 30rpx;
	}
</style>